﻿using System;
using DevelopTool.Common;
using DevelopTool.Forms.BaseForms;
using Sunny.UI;

namespace DevelopTool.Forms.EncodOrEncrypForms
{
    /// <summary>
    /// URL编码/解码
    /// </summary>
    public partial class UrlEncodeForm : BaseUIPage
    {
        public UrlEncodeForm()
        {
            InitializeComponent();
        }

        private void UrlEncodeForm_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 编码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEncode_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.codeEditorIn.ContentText))
            {
                this.ShowWarningNotifier("请输入需要编码的URL文本");
                return;
            }
            try
            {
                this.codeEditorOut.ContentText = StringHelper.UrlEncode(this.codeEditorIn.ContentText);
                this.ShowWarningTip(this.btnEncode, "已编码");
            }
            catch (Exception ex)
            {
                this.ShowErrorDialog(ex.Message);
            }
        }

        /// <summary>
        /// 解码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDecode_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.codeEditorIn.ContentText))
            {
                this.ShowWarningNotifier("请输入需要解码的URL文本");
                return;
            }
            try
            {
                this.codeEditorOut.ContentText = StringHelper.UrlDecode(this.codeEditorIn.ContentText);
                this.ShowWarningTip(this.btnDecode, "已解码");
            }
            catch (Exception ex)
            {
                this.ShowErrorDialog(ex.Message);
            }
        }
    }
}
